using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DeskNotes
{
    public partial class UpgradeDataStorageDlg : Form
    {
        public UpgradeDataStorageDlg()
        {
            InitializeComponent();
        }

        internal string OldDataFile
        {
            set
            {
                lblOldDataFile.Text = value;
                FileInfo f = new FileInfo(value);
                storageControl.DataFileName = f.DirectoryName;
            }
        }
        internal string OldArchiveFile
        {
            set
            {
                lblOldArchiveFile.Text = value;
                FileInfo f = new FileInfo(value);
                storageControl.ArchiveFileName = f.DirectoryName;
            }
        }
        /// <summary>
        /// Performs check on validity of names. Archive cannot be same as datafile
        /// New and old files should be different.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void storageControl_Leave(object sender, EventArgs e)
        {
            bool sameDataFile = false;
            bool sameArchiveFile = false;
            bool sameDataAndArchive = false;
            if (string.Equals(lblOldDataFile.Text, storageControl.DataFileName, StringComparison.OrdinalIgnoreCase))
                sameDataFile = true;
            if (string.Equals(lblOldArchiveFile.Text, storageControl.ArchiveFileName, StringComparison.OrdinalIgnoreCase))
                sameArchiveFile = true;
            if (string.Equals(storageControl.ArchiveFileName, storageControl.DataFileName, StringComparison.OrdinalIgnoreCase))
                sameDataAndArchive = true;
            if (sameDataFile || sameArchiveFile || sameDataAndArchive)
            {
                MessageBox.Show(this, Resources.AppResource.DataFilesMustDiffer, Resources.AppResource.APP_TITLE,
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
    }
}